﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Power.Common;
using Power.Models;
using Power.View.Dialog;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System;
using static Power.ViewModel.AIDistinguishDetailViewModel;
using static Power.ViewModel.AIDistinguishViewModel;

namespace Power.ViewModel.Dialog
{
    public class AddDefectsViewModel : ViewModelBase
    {
        private AddDefects model;
        public AddDefectsViewModel(AddDefects model,ImageSource image, DefectEntity defectEntity)
        {
            this.model = model;
            Close = new RelayCommand(OnClose);
            CloseOK = new RelayCommand(OnCloseOK);
            this.model.defectImage.ImageSource = image;
            this.Data = new AddDefectsData
            {
                DefectModel = defectEntity,
                //DefectModel = new DefectEntity() {  PicName = "", Name = "0", Level = 0, Length=0,
                //    StartPos = 0, EndPos = 0, Type = "0", CircleDirection = "0", DetectDate = DateTime.Now.Date.ToString("yyyy/MM/dd"), Describe = "描述2", PicUri = "/Resources/images/defects.png"
                //},
                //名称下拉框1
                SelectList1 = new List<SelectListItem>() { new SelectListItem { SelectItem = "名称1", SelectID = "0" },
                    new SelectListItem { SelectItem = "名称2", SelectID = "1" }, new SelectListItem { SelectItem = "名称3", SelectID = "2" },
                    new SelectListItem { SelectItem = "名称4", SelectID = "3" }},
                //类型下拉框2
                SelectList2 = new List<SelectListItem>() { new SelectListItem { SelectItem = "类型1", SelectID = "0" },
                    new SelectListItem { SelectItem = "类型2", SelectID = "1" }, new SelectListItem { SelectItem = "类型3", SelectID = "2" },
                    new SelectListItem { SelectItem = "类型4", SelectID = "3" }},
                //等级下拉框3
                SelectList3 = new List<SelectListItem>() { new SelectListItem { SelectItem = "等级1", SelectID = "0" },
                    new SelectListItem { SelectItem = "等级2", SelectID = "1" }, new SelectListItem { SelectItem = "等级3", SelectID = "2" },
                    new SelectListItem { SelectItem = "等级4", SelectID = "3" }}
            };
        }

        private void OnClose()
        {
            this.model.DialogResult = false;
            this.model.Close();
        }

        private void OnCloseOK()
        {
            MessagePrompt box = new MessagePrompt("是否提交缺陷？", true);
            var flag = box.ShowDialog();
            if (flag == true) { 
                //保存缺陷
            }
            this.model.Close();
        }

        #region 
        public RelayCommand Close { get; private set; }
        public RelayCommand CloseOK { get; private set; }

        public AddDefectsData Data { get; private set; }
        #endregion

        public class AddDefectsData : Power.Models.BaseModel
        {
            private DefectEntity defectModel;
            public DefectEntity DefectModel
            {
                get
                {
                    return defectModel;
                }
                set
                {
                    defectModel = value;
                    RaisePropertyChanged();
                }
            }
            private List<SelectListItem> selectList1;
            public List<SelectListItem> SelectList1
            {
                get => selectList1;
                set
                {
                    selectList1 = value;
                    RaisePropertyChanged();
                }
            }

            private List<SelectListItem> selectList2;
            public List<SelectListItem> SelectList2
            {
                get => selectList2;
                set
                {
                    selectList2 = value;
                    RaisePropertyChanged();
                }
            }

            private List<SelectListItem> selectList3;
            public List<SelectListItem> SelectList3
            {
                get => selectList3;
                set
                {
                    selectList3 = value;
                    RaisePropertyChanged();
                }
            }

        }
    }
}
